﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace httphelper.Control
{
    public partial class SuperWebBrowser : WebBrowser
    {
        public SuperWebBrowser()
        {
            InitializeComponent();
           // this.ScriptErrorsSuppressed = true;
        }
        /// <summary>
        /// 设置cookie
        /// </summary>
        /// <param name="lpszUrlName">url地址</param>
        /// <param name="lbszCookieName"></param>
        /// <param name="lpszCookieData"></param>
        /// <returns></returns>
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);

        /// <summary>
        /// 静态方法，设置cookie
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cookieName"></param>
        /// <param name="cookieValue"></param>
        /// <returns></returns>
        public bool SetCookie(string url, string cookieName, string cookieValue)
        {
            return InternetSetCookie(url, cookieName, cookieValue);
        }
        /// <summary>
        /// 静态方法，设置JSESSIONID
        /// </summary>
        /// <param name="url"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetJSESSIONID(string url, string value)
        {
            return SetCookie(url, "JSESSIONID", value);
        }
        /// <summary>
        /// 执行javascript语句
        /// </summary>
        /// <param name="script"></param>
        public void executeScript(String script)
        {
            String str = "javascript:" + script + ";zwyzwyerr();";
            Navigate(str);
        }

    }
}
